from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-12 14:08:52.176872
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 12, Sep, 2022
Time: 14:09:00
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4046
Nobs: 777.000 HQIC: -50.7364
Log likelihood: 9959.04 FPE: 7.50562e-23
AIC: -50.9438 Det(Omega_mle): 6.68965e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298196 0.054226 5.499 0.000
L1.Burgenland 0.107586 0.036097 2.980 0.003
L1.Kärnten -0.106666 0.019189 -5.559 0.000
L1.Niederösterreich 0.206423 0.075542 2.733 0.006
L1.Oberösterreich 0.113218 0.073069 1.549 0.121
L1.Salzburg 0.253546 0.038635 6.563 0.000
L1.Steiermark 0.035927 0.050368 0.713 0.476
L1.Tirol 0.106405 0.040816 2.607 0.009
L1.Vorarlberg -0.060515 0.035112 -1.723 0.085
L1.Wien 0.050411 0.064983 0.776 0.438
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058634 0.112559 0.521 0.602
L1.Burgenland -0.033608 0.074928 -0.449 0.654
L1.Kärnten 0.047529 0.039831 1.193 0.233
L1.Niederösterreich -0.176938 0.156804 -1.128 0.259
L1.Oberösterreich 0.396591 0.151672 2.615 0.009
L1.Salzburg 0.289259 0.080196 3.607 0.000
L1.Steiermark 0.106285 0.104551 1.017 0.309
L1.Tirol 0.313688 0.084722 3.703 0.000
L1.Vorarlberg 0.027313 0.072884 0.375 0.708
L1.Wien -0.021655 0.134886 -0.161 0.872
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191475 0.027840 6.878 0.000
L1.Burgenland 0.089679 0.018532 4.839 0.000
L1.Kärnten -0.008467 0.009851 -0.859 0.390
L1.Niederösterreich 0.260963 0.038783 6.729 0.000
L1.Oberösterreich 0.133726 0.037514 3.565 0.000
L1.Salzburg 0.046036 0.019835 2.321 0.020
L1.Steiermark 0.018162 0.025859 0.702 0.482
L1.Tirol 0.092971 0.020955 4.437 0.000
L1.Vorarlberg 0.058370 0.018027 3.238 0.001
L1.Wien 0.118154 0.033362 3.542 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108696 0.028343 3.835 0.000
L1.Burgenland 0.046816 0.018868 2.481 0.013
L1.Kärnten -0.015067 0.010030 -1.502 0.133
L1.Niederösterreich 0.191201 0.039485 4.842 0.000
L1.Oberösterreich 0.290298 0.038192 7.601 0.000
L1.Salzburg 0.112054 0.020194 5.549 0.000
L1.Steiermark 0.102475 0.026327 3.892 0.000
L1.Tirol 0.111233 0.021334 5.214 0.000
L1.Vorarlberg 0.069611 0.018353 3.793 0.000
L1.Wien -0.017970 0.033966 -0.529 0.597
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131020 0.051447 2.547 0.011
L1.Burgenland -0.050792 0.034247 -1.483 0.138
L1.Kärnten -0.040210 0.018205 -2.209 0.027
L1.Niederösterreich 0.170379 0.071670 2.377 0.017
L1.Oberösterreich 0.138969 0.069324 2.005 0.045
L1.Salzburg 0.287199 0.036655 7.835 0.000
L1.Steiermark 0.034672 0.047787 0.726 0.468
L1.Tirol 0.161310 0.038724 4.166 0.000
L1.Vorarlberg 0.100747 0.033313 3.024 0.002
L1.Wien 0.068565 0.061652 1.112 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056404 0.040950 1.377 0.168
L1.Burgenland 0.040157 0.027259 1.473 0.141
L1.Kärnten 0.050655 0.014491 3.496 0.000
L1.Niederösterreich 0.220973 0.057046 3.874 0.000
L1.Oberösterreich 0.283204 0.055179 5.132 0.000
L1.Salzburg 0.045664 0.029176 1.565 0.118
L1.Steiermark -0.001096 0.038036 -0.029 0.977
L1.Tirol 0.147785 0.030822 4.795 0.000
L1.Vorarlberg 0.072964 0.026515 2.752 0.006
L1.Wien 0.084110 0.049072 1.714 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180300 0.049031 3.677 0.000
L1.Burgenland -0.006284 0.032639 -0.193 0.847
L1.Kärnten -0.061290 0.017350 -3.533 0.000
L1.Niederösterreich -0.084139 0.068304 -1.232 0.218
L1.Oberösterreich 0.195900 0.066068 2.965 0.003
L1.Salzburg 0.056577 0.034933 1.620 0.105
L1.Steiermark 0.231341 0.045542 5.080 0.000
L1.Tirol 0.493499 0.036905 13.372 0.000
L1.Vorarlberg 0.048257 0.031748 1.520 0.129
L1.Wien -0.051983 0.058756 -0.885 0.376
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166427 0.056267 2.958 0.003
L1.Burgenland -0.010360 0.037456 -0.277 0.782
L1.Kärnten 0.067046 0.019911 3.367 0.001
L1.Niederösterreich 0.206054 0.078385 2.629 0.009
L1.Oberösterreich -0.070575 0.075819 -0.931 0.352
L1.Salzburg 0.211519 0.040089 5.276 0.000
L1.Steiermark 0.115621 0.052264 2.212 0.027
L1.Tirol 0.071971 0.042352 1.699 0.089
L1.Vorarlberg 0.121607 0.036434 3.338 0.001
L1.Wien 0.122294 0.067428 1.814 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357486 0.032562 10.979 0.000
L1.Burgenland 0.005596 0.021676 0.258 0.796
L1.Kärnten -0.023330 0.011522 -2.025 0.043
L1.Niederösterreich 0.215057 0.045361 4.741 0.000
L1.Oberösterreich 0.187343 0.043876 4.270 0.000
L1.Salzburg 0.046601 0.023199 2.009 0.045
L1.Steiermark -0.016097 0.030245 -0.532 0.595
L1.Tirol 0.106392 0.024509 4.341 0.000
L1.Vorarlberg 0.073709 0.021084 3.496 0.000
L1.Wien 0.048560 0.039021 1.244 0.213
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040194 0.148708 0.191949 0.157033 0.124141 0.112917 0.066075 0.222724
Kärnten 0.040194 1.000000 -0.003921 0.132007 0.041711 0.095649 0.430427 -0.052299 0.100098
Niederösterreich 0.148708 -0.003921 1.000000 0.337172 0.151715 0.298157 0.108113 0.183411 0.323570
Oberösterreich 0.191949 0.132007 0.337172 1.000000 0.227669 0.330377 0.172313 0.167946 0.264731
Salzburg 0.157033 0.041711 0.151715 0.227669 1.000000 0.147039 0.122714 0.147439 0.133530
Steiermark 0.124141 0.095649 0.298157 0.330377 0.147039 1.000000 0.151493 0.138442 0.079195
Tirol 0.112917 0.430427 0.108113 0.172313 0.122714 0.151493 1.000000 0.115032 0.153640
Vorarlberg 0.066075 -0.052299 0.183411 0.167946 0.147439 0.138442 0.115032 1.000000 0.006862
Wien 0.222724 0.100098 0.323570 0.264731 0.133530 0.079195 0.153640 0.006862 1.000000